//
//  StudentInfoController.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/5/24.
//  Copyright © 2017年 蓝布鲁. All rights reserved.
//

#import "StudentInfoController.h"
#import "StudentInfoModel.h"
#import "StudentInfoHeaderView.h"

@interface StudentInfoController () <UITableViewDelegate, UITableViewDataSource>

// UI
@property (nonatomic,retain)UITableView *tableView;
@property (nonatomic,retain)StudentInfoHeaderView *headerView;

// 数据
@property (nonatomic,retain)StudentInfoModel *model;

@end

@implementation StudentInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"学生信息";
    
    // 获取网络数据
    [self getStudentInfo];
    
    // 初始化头部
    [self setupHeader];
    
    // 初始化tableView
    [self setupTableView];
}

-(void)setupTableView {
    // 设置TableView
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64 + 80, SCREEN_WIDTH, SCREEN_HEIGHT - 80) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
}

-(void)setupHeader {
    self.headerView = [[StudentInfoHeaderView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 80)];
    [self.view addSubview:self.headerView];
}
#pragma mark - 获取网络数据
-(void)getStudentInfo {
    [[NetworkTool shareInstance] requireMethodType:POSTType
                                         URLString:@"SDSY/TgetOneStudent"
                                        parameters:@{@"sid": @(self.sid)}
                                           success:^(NSDictionary *respondDictionary) {
                                               self.model = [[StudentInfoModel alloc] initWithDictionary:respondDictionary];
                                               
                                               self.headerView.model = self.model;
                                               [self.tableView reloadData];
                                           } failure:^(NSError *error) {
                                               NSLog(@"%@",error);
                                               [SVProgressHUD showfailed];
                                           }];
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELLID"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"CELLID"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row == 0) { // 学校
        cell.textLabel.text = @"学校";
        cell.detailTextLabel.text = self.model.school;
    }else if (indexPath.row == 1) { // 学院
        cell.textLabel.text = @"学院";
        cell.detailTextLabel.text = self.model.college;
    }else if(indexPath.row == 2) { // 班级
        cell.textLabel.text = @"班级";
        cell.detailTextLabel.text = self.model.sclass;
    }else if(indexPath.row == 3) { // 班级类型
        cell.textLabel.text = @"班级类型";
        cell.detailTextLabel.text = self.model.sclasstype;
    }else if(indexPath.row == 4) { // 学号
        cell.textLabel.text = @"学号";
        cell.detailTextLabel.text = self.model.sid;
    }else if(indexPath.row == 5) { // 手机号
        cell.textLabel.text = @"手机号";
        cell.detailTextLabel.text = self.model.phone;
    }
    
    return cell;
}

@end
